package com.yuwen.conf;

import org.apache.catalina.filters.CorsFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

@Configuration
public class CorsConfig {
    private CorsConfiguration buildconfig(){
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*");// 1允许任何域名使用corsconfiguration.addAllowedHeader("* "');1/ 2允许任何头
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        return corsConfiguration;
    }

//    @Bean
//        //需要倒的包import org.springframework.web.filter.CorsFilter;
//    CorsFilter getCorsFilter(){
//        //需要倒的包：import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//        CorsConfiguration corsConfiguration = new CorsConfiguration();
//        //允许的域
//        corsConfiguration.addAllowedOrigin("*");
//        //允许跨域的方法
//        corsConfiguration.addAllowedMethod("*");
//        //允许跨域的请求头
//        corsConfiguration.addAllowedHeader("*");
//        //允许跨域的路径
//        source.registerCorsConfiguration("/**",corsConfiguration);
//        return new CorsFilter();
//    }
}
